function getCookies(name){
    var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length + 1;
    if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
        return null;
    if ( start == -1 ) 
        return null;
    var end = document.cookie.indexOf( ";", len );
    if ( end == -1 ) 
        end = document.cookie.length;
    return unescape( document.cookie.substring( len, end ) );
};
/*-----------------------------*/
var url = 'http://' + window.location.host + '/';
var ZingD = ['www'];
var ZingT = ['Trang chủ RapPhim'];

var ZingCopyright = 'Copyright © RapPhim<br />Các tập phim được thành viên rapphim.org tổng hợp từ các nguồn trên mạng.<br />All clips are collected from and hosted by Google, Youtube, DailyMotion... rapphim.org is not liable for copyright by any country{web.QueryNum}';
/*-----------------------------*/
function setHomePage(){
    if(document.all){
        var homepage = document.getElementById('rapphim_homepage');
        if(!homepage)
            return;
        var ishp = false;
        for(var i=0;i<ZingD.length;i++)                     /*Check homepage*/
        {
            if(homepage.isHomePage('http://' + ZingD[i] + '.rapphim.org/'))
            {
                ishp = true;
                break;
            }
        }  
        if(!ishp){
            homepage.style.behavior='url(#default#homepage)';            
            homepage.setHomePage(url);                  /*Set homepage*/
        }
    }
    else
        alert('Chọn Tools > Option > Main > Use Current Page (Alt+C) để đặt trang chủ!');
};
function addFavorite(){
    var title='RapPhim';
    for(var i=0;i<ZingD.length;i++)                     /*Check homepage*/
    {
        if(url.indexOf(ZingD[i])>-1)
        {
            title = ZingT[i];
            break;
        }
    }  
    if(document.all)
        window.external.AddFavorite(url,title);
	else if (window.sidebar)
        window.sidebar.addPanel(title, url, "")
};
/*-----------------------------*/
function zshowHeader(dID){
    dID = document.getElementById(dID); 
    if(!dID)
        return;
    var str ='';
    for(var i=0;i<ZingD.length;i++)
	{
		var zd = ZingD[i];
		var zt = ZingT[i];
		if(zd=='mail')
			str += '<a href="http://'+zd+'.zing.vn/cgi-bin/login?V=1011" target="_blank" onClick="javascript: firstTracker._trackPageview(\'/header/mail.zing.vn/cgi-bin/login?V=1011\');secondTracker._trackPageview(\'/header/mail.zing.vn/cgi-bin/login?V=1011\');"><span id="zmail2711">'+zt+'</span></a> | ';
		else if(zd=='www')
		    str += '<a href="http://rapphim.org/" target="_blank">'+zt+'</a>';

	}
    dID.innerHTML = str;
};
function cboZfChange(_th){
    var i = _th.selectedIndex;
    if(i==0)
        return;
    window.location.href = _th[i].value;
};
function _zproducts(){
	var str = '<select onchange="cboZfChange(this);"><option value="">Các dịch vụ khác</option>';
	str += '<option value="http://tv.rapphim.org">TV Online</option>';
	str += '<option value="http://clip.rapphim.org">Video Clip</option>';
	str += '<option value="http://games.rapphim.org">Games</option>';
	str += '<option value="http://dienanh.rapphim.org">Điện Ảnh</option>';
	str += '</select>';
	return str;
};
function zshowFooter(dID){
    dID = document.getElementById(dID); 
    if(!dID)
        return;
    dID.innerHTML = _zproducts();
};
function zshowCopyright(dID){
    dID = document.getElementById(dID); 
    if(!dID)
        return;
    dID.innerHTML = ZingCopyright;
	/*----------------*/
	//var skey = getCookies('skey');
	//if(skey==null || skey=='')
	//    return;
	/*----------------*/
	//notify_new_mail();
	//var script = document.createElement("script");
	//script.setAttribute("src","http://mail.zing.vn/cgi-bin/unreadnum?callback=notify_new_mail");
	//script.setAttribute("type","text/javascript");
	//document.getElementsByTagName('head')[0].appendChild(script); 
};
function zshowProducts(dID){
    dID = document.getElementById(dID); 
    if(!dID)
        return;
    var str = '<p>Một dịch vụ của PN Group</p>';
    str += '<p>' + _zproducts() + '</p>';
    dID.innerHTML = str;
};
function zcreFlash(src_,clickTag,width,height){
    var HTML =  '<object align="baseline" border="0" classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" ';
    if (width!=0)
        HTML += ' width="' + width + '"';
    else 
        HTML += ' width="200"';
    if (height!=0)
        HTML += ' height="' + height + '"';
    else 
        HTML += ' height="150"';
    HTML += ' >';
    HTML += '<param name="_cx" value="5292" /><param name="_cy" value="3969" />';
    HTML += '<param name="Movie" value="' + src_ + '" />';
    HTML += '<param name="Src" value="' + src_ + '" />';
    HTML += '<param name="WMode" value="Transparent" /><param name="Play" value="-1" />';
    HTML += '<param name="Loop" value="-1" /><param name="Quality" value="High" />';
    HTML += '<param name="SAlign" value="" /><param name="Menu" value="-1" />';
    HTML += '<param name="Base" value="" /><param name="AllowScriptAccess" value="always" />';
    HTML += '<param name="Scale" value="ShowAll" /><param name="DeviceFont" value="0" />';
    HTML += '<param name="EmbedMovie" value="0" /><param name="BGColor" value="" />';
    HTML += '<param name="SWRemote" value="" />';
	if(clickTag.length != '')
		HTML += '<param name="flashvars" value="clickTAG='+clickTag+'" />';
    HTML += '<embed src="' + src_ + '"';
    HTML += ' wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer"'; 
    HTML += ' type="application/x-shockwave-flash"'; 
    HTML += ' name="AdObj1" quality="High"';
    if (width!=0)
        HTML += ' width="' + width + '"';
    else 
        HTML += ' width="200"';
    if (height!=0)
        HTML += ' height="' + height + '"';
    else 
        HTML += ' height="150"';
	if(clickTag.length != '')
		HTML += ' flashvars="clickTAG='+clickTag+'"';
    HTML += ' >';
    HTML += '</object>';
    return HTML;
};
function showBanner(boxID,width,height,arrAd,brand){
    var n = arrAd.length;
    var rand = 0;
    if(!brand)
    {
        rand = Math.floor(Math.random()*n+1); 
        rand = arrAd[rand%n];
    }
    var innerboxID = document.getElementById(boxID);
    switch(rand[0])
    {
        case 'adz':
            selectAd(rand[1],boxID);
            break;
        case 'fla':
			if(rand.length>2)
				innerboxID.innerHTML = zcreFlash(rand[1],rand[2],width,height); 
			else
				innerboxID.innerHTML = zcreFlash(rand[1],'',width,height);
            break;
        case 'img':
            innerboxID.innerHTML = '<a href="'+rand[1]+'" target="_blank"><img src="'+rand[2]+'" width="'+width+'px" height="'+height+'px" alt="" /></a>';
            break;
        case 'ifr':
            innerboxID.innerHTML = rand[1];
            break;
        case 'htm':
            innerboxID.innerHTML = rand[1];
            break;
    }
};
function showmenu(li){
    if(li.className != 'show')
        li.className = 'show';
    else
        li.className = '';
};
function czshowHeader(dID){
    var ul = document.getElementById(dID);
    var mLength = 4;   
    var ul2 = document.createElement('ul');
    for(var i=0;i<ZingD.length;i++){
	    var li = document.createElement('li');
	    li.innerHTML = czgetLink(ZingD[i],ZingT[i]);
        if(i<mLength)
            ul.appendChild(li);
        else
            ul2.appendChild(li);
    }
    //----------------------
    var li2 = document.createElement('li');
    li2.onclick = function(){
        showmenu(this); 
    }
    var a = document.createElement('a');
    a.href="javascript:;";
    a.innerHTML = 'Khác <small>▼</small>';
    li2.appendChild(a);
    li2.appendChild(ul2);
    ul.appendChild(li2);
};
function czgetLink(zd,zt){
    if(zd=='mail')
	    return '<a href="http://'+zd+'.zing.vn/cgi-bin/login?V=1011" target="_blank" onClick="javascript: firstTracker._trackPageview(\'/header/mail.zing.vn/cgi-bin/login?V=1011\');secondTracker._trackPageview(\'/header/mail.zing.vn/cgi-bin/login?V=1011\');"><span id="zmail2711">'+zt+'</span></a>';
    else if(zd=='www')
        return '<a href="http://'+zd+'.zing.vn/" target="_blank" onClick="javascript: firstTracker._trackPageview(\'/header/www.zing.vn/\');secondTracker._trackPageview(\'/header/www.zing.vn/\');">'+zt+'</a>';
    else if(zd=="me")
	    return '<a href="http://'+zd+'.zing.vn/" target="_blank" onClick="javascript: firstTracker._trackPageview(\'/header/'+zd+'.zing.vn/\');secondTracker._trackPageview(\'/header/'+zd+'.zing.vn/\');">'+zt+' <img src="http://zing.vn/zing/images/new.gif" alt="" /></a>';
	else if(zd=="123mua")
	    return '<a href="http://123mua.com.vn" target="_blank" onClick="javascript: firstTracker._trackPageview(\'/header/123mua.com.vn\');secondTracker._trackPageview(\'/header/123mua.com.vn\');">123Mua</a>';
    else
	    return '<a href="http://'+zd+'.zing.vn/" target="_blank" onClick="javascript: firstTracker._trackPageview(\'/header/'+zd+'.zing.vn/\');secondTracker._trackPageview(\'/header/'+zd+'.zing.vn/\');">'+zt+'</a>';
};
/*
function notify_new_mail(obj,containerID){
    var unread=0;
    if(obj){
		if(obj.unread>=0)
		    unread = obj.unread;
	}
	if(typeof(containerID)==undefined || containerID==null)
	    containerID = 'zmail2711';
	document.getElementById(containerID).innerHTML = 'Mail <b>('+unread+')</b>';
};
*/
function zpopupFeedback(){
    var _reg = new RegExp(/^https?\:\/\/(?:.*\.)?([^\.]+)\.zing\.vn.*?$/ig); 
    var _reg = _reg.exec(location.href);
    var product = 'www';
    if(_reg)
        product = _reg[1].toLowerCase();
    var datenow_ = new Date();
    var rand = datenow_.getDate();
    rand += datenow_.getHours();
    rand += datenow_.getMinutes();
    rand += datenow_.getSeconds();
    rand += datenow_.getTime();
    zpopupWindow('http://www.zing.vn/feedback/?p=' + product + '&r=' + rand, false, true, true, false, false, false, true, true, 550, 524, 0, 0);
};
function zpopupWindow(url, isStatus, isResizeable, isScrollbars, isToolbar, isLocation, isFullscreen, isTitlebar, isCentered, width, height, top, left)
{
	if (isCentered)
	{
		top = (screen.height - height) / 2;
		left = (screen.width - width) / 2;
	}
	window.open(url, '_blank', 'status=' + (isStatus ? 'yes' : 'no') + ','
	+ 'resizable=' + (isResizeable ? 'yes' : 'no') + ','
	+ 'scrollbars=' + (isScrollbars ? 'yes' : 'no') + ','
	+ 'toolbar=' + (isToolbar ? 'yes' : 'no') + ','
	+ 'location=' + (isLocation ? 'yes' : 'no') + ','
	+ 'fullscreen=' + (isFullscreen ? 'yes' : 'no') + ','
	+ 'titlebar=' + (isTitlebar ? 'yes' : 'no') + ','
	+ 'height=' + height + ',' + 'width=' + width + ','
	+ 'top=' + top + ',' + 'left=' + left);
};





var Ovr2='';
if(typeof document.compatMode!='undefined'&&document.compatMode!='BackCompat')
{
        cot_t1_DOCtp="_top:expression(document.documentElement.scrollTop+document.documentElement.clientHeight-this.clientHeight);_left:expression(document.documentElement.scrollLeft + document.documentElement.clientWidth - offsetWidth);}";
}
else
{
        cot_t1_DOCtp="_top:expression(document.body.scrollTop+document.body.clientHeight-this.clientHeight);_left:expression(document.body.scrollLeft + document.body.clientWidth - offsetWidth);}";
}
if(typeof document.compatMode!='undefined'&&document.compatMode!='BackCompat')
{
        cot_t1_DOCtp2="_top:expression(document.documentElement.scrollTop-20+document.documentElement.clientHeight-this.clientHeight);}";
}
else
{
        cot_t1_DOCtp2="_top:expression(document.body.scrollTop-20+document.body.clientHeight-this.clientHeight);}";
}

var cot_bgf0=(window.location.protocol.toLowerCase()=="https:")? "https://secure.comodo.net/trustlogo/images/cot_bgf0.gif" : "http://www.trustlogo.com/images/cot_bgf0.gif";

var cot_tl_bodyCSS='* html {background:url('+cot_bgf0+') fixed;background-repeat: repeat;background-position: right bottom;}';

var cot_tl_fixedCSS='#cot_tl_fixed{position:fixed;';
var cot_tl_fixedCSS=cot_tl_fixedCSS+'_position:absolute;';
var cot_tl_fixedCSS=cot_tl_fixedCSS+'bottom:0px;';
var cot_tl_fixedCSS=cot_tl_fixedCSS+'right:0px;';
var cot_tl_fixedCSS=cot_tl_fixedCSS+'clip:rect(0 100 100 0);';
var cot_tl_fixedCSS=cot_tl_fixedCSS+cot_t1_DOCtp;
var cot_tl_popCSS='#cot_tl_pop {background-color: transparent;';
var cot_tl_popCSS=cot_tl_popCSS+'position:fixed;';
var cot_tl_popCSS=cot_tl_popCSS+'_position:absolute;';
var cot_tl_popCSS=cot_tl_popCSS+'height:194px;';
var cot_tl_popCSS=cot_tl_popCSS+'width: 244px;';
var cot_tl_popCSS=cot_tl_popCSS+'right: 120px;';
var cot_tl_popCSS=cot_tl_popCSS+'bottom: 20px;';
var cot_tl_popCSS=cot_tl_popCSS+'overflow: hidden;';
var cot_tl_popCSS=cot_tl_popCSS+'visibility: hidden;';
var cot_tl_popCSS=cot_tl_popCSS+'z-index: 100;';
var cot_tl_popCSS=cot_tl_popCSS+cot_t1_DOCtp2;
document.write('<style type="text/css">'+cot_tl_bodyCSS+cot_tl_fixedCSS+cot_tl_popCSS+'</style>');

/*function cot_tl_bigPopup(url)
{
        newwindow=window.open(url,'name','WIDTH=450,HEIGHT=500,FRAMEBORDER=0,MARGINWIDTH=0,MARGINHEIGHT=0,SCROLLBARS=1,allowtransparency=true');
        if(window.focus)
        {
                newwindow.focus()
        }
        return false;
}

function cot_tl_toggleMiniPOPUP_hide()
{
        var cred_id='cot_tl_pop';
        var NNtype='hidden';
        var IEtype='hidden';
        var WC3type='hidden';
        if(document.getElementById){eval("document.getElementById(cred_id).style.visibility=\""+WC3type+"\"");
        }else{if(document.layers){document.layers[cred_id].visibility=NNtype;
        }else{if(document.all){eval("document.all."+cred_id+".style.visibility=\""+IEtype+"\"");
        }}}document.getElementById('frame_pop').src =cot_tl_dummyMini;
}

function cot_tl_toggleMiniPOPUP_show()
{
        cred_id='cot_tl_pop';
        var NNtype='show';
        var IEtype='visible';
        var WC3type='visible';
        if(document.getElementById)
        {
                eval("document.getElementById(cred_id).style.visibility=\""+WC3type+"\"");
        }
        else
        {
                if(document.layers)
                {
                        document.layers[cred_id].visibility=NNtype;
                }
                else
                {
                        if(document.all)
                        {
                                eval("document.all."+cred_id+".style.visibility=\""+IEtype+"\"");
                        }
                }
        }
        
        document.getElementById('frame_pop').src =cot_tl_miniBaseURL;
}*/

function COT(cot_tl_theLogo,cot_tl_LogoType,LogoPosition,theAffiliate)
{
        if (document.getElementById('comodoTL'))
                {document.getElementById('comodoTL').style.display="none";
        }
        host=location.host;
        if(window.location.protocol.toLowerCase()=="https:")
        {
                cot_tl_dummyMini='https://secure.comodo.net/trustlogo/images/cot_bgf0.gif';
                cot_tl_miniBaseURL='https://secure.comodo.net/ttb_searcher/trustlogo?v_querytype=C&v_shortname='+cot_tl_LogoType+'&v_search='+host+'&x=6&y=5';
                cot_tl_bigBaseURL='https://secure.comodo.net/ttb_searcher/trustlogo?v_querytype=W&v_shortname='+cot_tl_LogoType+'&v_search='+host+'&x=6&y=5';
        }
        else
        {
                cot_tl_dummyMini='http://www.trustlogo.com/images/cot_bgf0.gif';
                cot_tl_miniBaseURL='http://www.trustlogo.com/ttb_searcher/trustlogo?v_querytype=C&v_shortname='+cot_tl_LogoType+'&v_search='+host+'&x=6&y=5';
                cot_tl_bigBaseURL='http://www.trustlogo.com/ttb_searcher/trustlogo?v_querytype=W&v_shortname='+cot_tl_LogoType+'&v_search='+host+'&x=6&y=5';
        };

        document.write('<div id="cot_tl_pop">');
        document.write('<IFRAME id="frame_pop" name="frame_pop" src="'+cot_tl_dummyMini+'" WIDTH=244 HEIGHT=194 FRAMEBORDER=0 MARGINWIDTH=0 MARGINHEIGHT=0 SCROLLING=no allowtransparency=true></IFRAME>');
        document.write('</div>');
        document.write('<div id="cot_tl_fixed">');
        document.write('<a href="http://rapphim.org/clip" onClick="return cot_tl_bigPopup(\''+cot_tl_bigBaseURL+'\')"><img src='+cot_tl_theLogo+' alt="Clip Vui" border="0" onMouseOver="Ovr=setTimeout(\'cot_tl_toggleMiniPOPUP_show()\',1000);clearTimeout(Ovr2)" onMouseOut="Ovr2=setTimeout(\'cot_tl_toggleMiniPOPUP_hide()\',3000);clearTimeout(Ovr)"></a>');
        document.write('</div>');
}
